//
//  LSZShowDetailsViewController.m
//  JKFuYinProject
//
//  Created by 九酷 on 2018/3/28.
//  Copyright © 2018年 LC. All rights reserved.
//

#import "LSZShowDetailsViewController.h"

@interface LSZShowDetailsViewController ()

@end

@implementation LSZShowDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    if (self.nameString.length<4) {
        self.title = [NSString stringWithFormat:@"%@提现",self.nameString];
    }else{
        self.title = self.nameString;
    }
    if ([self.nameString isEqualToString:@"支付宝"]) {
        self.arrayTitle = @[@"提现金额:",@"真实姓名:",@"手机号或邮箱:"];
    }else if([self.nameString isEqualToString:@"微信"]){
         self.arrayTitle = @[@"提现金额:",@"真实姓名:",@"手机或微信号:"];
    }
    else{
         self.arrayTitle = @[@"充值金额:",@"真实姓名:",@"手机号:"];
    }
    [self initWithUIShowDetails];
}
#pragma mark - 支付宝或者微信转账
#pragma mark - UI订单详情
-(void)initWithUIShowDetails
{
    self.tableViewShowDetails = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-HOME_INDICATOR_HEIGHT) style:UITableViewStyleGrouped];
    self.tableViewShowDetails.delegate = self;
    self.tableViewShowDetails.dataSource = self;
    self.tableViewShowDetails.estimatedRowHeight=0;
    self.tableViewShowDetails.estimatedSectionFooterHeight =0;
    self.tableViewShowDetails.estimatedSectionHeaderHeight =0;
    self.tableViewShowDetails.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableViewShowDetails];
    [self.tableViewShowDetails registerClass:[LSZWithdrawalInformationTableViewCell class] forCellReuseIdentifier:@"LSZWithdrawalInformationTableViewCell"];
    [self.tableViewShowDetails registerClass:[LSZPersonalInformationTableViewCell class] forCellReuseIdentifier:@"LSZPersonalInformationTableViewCell"];
    [self.tableViewShowDetails registerClass:[LSZPayFootCell class] forHeaderFooterViewReuseIdentifier:@"LSZPayFootCell"];

    UITapGestureRecognizer * singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickShowMoney)];
     [self.view addGestureRecognizer:singleTap];
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.00001;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1){
        if(ScreenWidth ==414){
            return  195;
        }else
        if(ScreenWidth ==375){
            return  195;
        }else{
            return  185;
        }
    }else if(indexPath.section == 2&&indexPath.row == 0){
        if(ScreenWidth ==414){
            return  [LSZSpecialPackaging caculateHeightOfText:ScreenWidth-20 height:10000 font:14.5 :self.promptString]+10;
        }else if(ScreenWidth ==375){
            return  [LSZSpecialPackaging caculateHeightOfText:ScreenWidth-20 height:10000 font:14 :self.promptString]+10;
        }else{
            return  [LSZSpecialPackaging caculateHeightOfText:ScreenWidth-20 height:10000 font:13.5 :self.promptString];
        }
    }else{
        if (ScreenWidth == 320) {
            //5
            return  50;
        }else if(ScreenWidth == 375){
            // 6 7
            return  55;
        }else {
            //plus
            return  60;
        }
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section == 3) {
        if (ScreenWidth == 320) {
            //5
             return 75;
        }else if(ScreenWidth == 375){
            // 6 7
              return 85;
        }else {
            //plus
            return 90;
        }
    }else{
        return  15;
    }
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(section == 2){
        return 2;
    }else{
        return 1;
    }
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        LSZWithdrawalInformationTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZWithdrawalInformationTableViewCell" forIndexPath:indexPath];
        cell.labelTitle.text = self.arrayTitle[indexPath.row];
        cell.textContent.hidden = YES;
        cell.labelMoney.hidden = NO;
        cell.labelMoney.text = [NSString stringWithFormat:@"%@元",self.moneyStr];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else if (indexPath.section == 1){
        LSZPersonalInformationTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZPersonalInformationTableViewCell" forIndexPath:indexPath];
        if (cell.textFieldName.text.length >0) {
            cell.textFieldName.text = cell.textFieldName.text;
            cell.textFieldName.textColor = titleColorLSZ;
        }else{
            cell.textFieldName.placeholder = @"请输入您的真实姓名";
            cell.textFieldName.textColor = lightColor;
        }
        if (cell.textFieldPhone.text.length >0) {
            cell.textFieldPhone.placeholder = cell.textFieldPhone.text;
            cell.textFieldPhone.textColor = titleColorLSZ;
        }else{
            cell.textFieldPhone.placeholder = @"请输入您的电话号码";
            cell.textFieldPhone.textColor = lightColor;
        }
        cell.textFieldPhone.delegate = self;
        cell.textFieldName.delegate = self;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else{
        UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellTiShi"];
        if (!cell) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellTiShi"];
        }
        cell.textLabel.font = [LSZSpecialPackaging setlabelTextFontAdaptiveSize:14.5];
        if (indexPath.section == 2&&indexPath.row == 0) {
            cell.textLabel.text = self.promptString;
            cell.textLabel.textColor = titleColorLSZ;
            cell.textLabel.numberOfLines = 0;
        }else{
            __weak typeof(self) weakSelf = self;
            if (indexPath.section == 2 && indexPath.row == 1) {
                cell.textLabel.text = @"点击复制客服微信号:shengjing2019";
                cell.textLabel.textColor = redUIColor;
                [cell.textLabel tapGesture:^(UIGestureRecognizer *ges) {
                    [weakSelf goToFuZhi];
                }];
                [LSZSpecialPackaging addThreadWithOtherRGB:cell.contentView A:20 B:0 C:ScreenWidth-40 D:1 R:241 G:241 BB:241];
            }
            if(indexPath.section == 3 && indexPath.row == 0){
                cell.textLabel.text = @"点击拨打客服电话:18614972438";
                cell.textLabel.textColor = lightColor;
                [cell.textLabel tapGesture:^(UIGestureRecognizer *ges) {
                    [weakSelf telPhone];
                }];
            }
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    if (section == 3) {
        LSZPayFootCell * cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"LSZPayFootCell"];
        [cell.butSave addTarget:self action:@selector(clickSave) forControlEvents:UIControlEventTouchUpInside];
        return cell;
    }else{
        UITableViewHeaderFooterView * cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"cell"];
        return cell;
    }
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section == 2&&indexPath.row == 1){
        [self goToFuZhi];
    }
    if(indexPath.section == 3&&indexPath.row == 0 ){
        [self telPhone];
    }
}
-(void)goToFuZhi
{
    UIPasteboard * pastboard = [UIPasteboard generalPasteboard];
    pastboard.string = @"shengjing2019";
    [self setStringWarning:@"已复制到剪切板!"];
}
-(void)telPhone
{
    NSMutableString * string = [[NSMutableString alloc] initWithFormat:@"tel:%@",@"18614972438"];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:string]];
}
#pragma mark - 保存按钮
-(void)clickSave
{
    __weak typeof(self) weakSelf = self;
    LSZPersonalInformationTableViewCell * cell = (LSZPersonalInformationTableViewCell *)[weakSelf.tableViewShowDetails cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0  inSection:1]];
    if ([cell.textFieldName.text isEqualToString:@""]||cell.textFieldName.text.length == 0) {
        [weakSelf initWithtring:@"请填写收款人的真实姓名!"];
        return;
    }
    if ([cell.textFieldPhone.text isEqualToString:@""]||cell.textFieldPhone.text.length == 0) {
        [weakSelf initWithtring:@"请填写收款人的账号!"];
        return;
    }
    NSScanner *scan = [NSScanner scannerWithString:cell.textFieldPhone.text];
    int val;
     BOOL isOk =  [scan scanInt:&val] && [scan isAtEnd];//是否是纯数字
    if (isOk == YES) {
        BOOL checkMobile = [LSZSpecialPackaging isValidateMobile:cell.textFieldPhone.text];
        if (checkMobile == NO) {
             [weakSelf initWithtring:@"请输入正确的手机号"];
            return;
        }
    }else{
        if ([self.typeStr isEqualToString:@"2"]) {
            BOOL isEmail = [LSZSpecialPackaging MailboxDiscriminationForStringsThatAreNotPureNumbers:cell.textFieldPhone.text];
            if (isEmail == NO) {
                [weakSelf initWithtring:@"请输入正确的邮箱地址!"];
                return;
            }
        }
    }
    [self clickShowMoney];
    [LSZRequestData alipayOrWeChatWithdrawal:weakSelf.moneyStr type:weakSelf.typeStr pay_to:cell.textFieldPhone.text pay_name:cell.textFieldName.text  :^(BOOL isOK, NSString * str, NSDictionary * dic) {
        if(isOK == YES ){
            [weakSelf initWithtring:str];
             LSZWithdrawalRecordManager * manager = [[LSZWithdrawalRecordManager alloc]initWithDrawalSuccess:dic];
            LSZDetailsWithdrawalOrderVC * vc = [[LSZDetailsWithdrawalOrderVC alloc]init];
            LSZWithdrawalRecordMg * mg = nil;
            mg = manager.arrayData[0];
            vc.withdrawalRecordMg = mg;
            [weakSelf.navigationController pushViewController:vc animated:YES];
         }else{
            [weakSelf initWithtring:str];
        }
    }];
}
-(void)clickShowMoney
{
    [self.view endEditing:YES];
}
@end
